package bb.lanxing.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.baidu.mapapi.search.core.PoiInfo;

import java.util.ArrayList;
import java.util.List;

import bb.lanxing.R;

public class POISearchResultAdapter extends BaseAdapter {

    private Context context;
    private List<PoiInfo> itemList = new ArrayList<>();

    public POISearchResultAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return itemList.size();
    }

    @Override
    public Object getItem(int position) {
        return itemList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_poi_search_result, parent, false);
        }

        // 绑定数据到视图
        TextView titleTextView = convertView.findViewById(R.id.poi_title);
        TextView descriptionTextView = convertView.findViewById(R.id.poi_city);

        PoiInfo item = itemList.get(position);
        titleTextView.setText(item.name);
        descriptionTextView.setText(item.city);

        return convertView;
    }

    public void updateData(List<PoiInfo> itemList) {
        this.itemList = itemList;
        notifyDataSetChanged();
    }
}